package com.atguigu.tingshu.dispatch.job;

import com.atguigu.tingshu.search.client.SearchFeignClient;
import com.atguigu.tingshu.user.client.UserFeignClient;
import com.xxl.job.core.context.XxlJobHelper;
import com.xxl.job.core.handler.annotation.XxlJob;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

@Slf4j
@Component

public class DispatchHandler {


    @XxlJob("hellojob")
    public void helloJobHandler() throws Exception {
        // 可参考Sample示例执行器中的示例任务"ShardingJobHandler"了解试用
        int shardIndex = XxlJobHelper.getShardIndex();
        int shardTotal = XxlJobHelper.getShardTotal();
        log.info("分片参数：当前分片序号 = {}, 总分片数 = {}", shardIndex, shardTotal);
        String jobParam = XxlJobHelper.getJobParam();
        if ("success".equals(jobParam)) {
            log.info("hello job......任务参数：{}", jobParam);
        } else if ("fail".equals(jobParam)) {
            int i = 1 / 0;
        }
    }


    @Autowired
    private SearchFeignClient searchFeignClient;


    /**
     * 每隔两小时触发：更新小时榜-排行榜任务
     * @throws Exception
     */
    @XxlJob("updateLatelyAlbumRanking")
    public void updateLatelyAlbumRanking() throws Exception {
        log.info("更新小时榜-排行榜任务触发了");
        searchFeignClient.updateLatelyAlbumRanking();
    }


    @Autowired
    private UserFeignClient userFeignClient;


    /**
     * 每天凌晨0点触发：更新VIP状态任务
     * @throws Exception
     */
    @XxlJob("updateVipExpireStatus")
    public void updateVipExpireStatus() throws Exception {
        log.info("更新VIP状态任务触发了");
        userFeignClient.updateVipExpireStatus();
    }

}
